package com.xinyue.game.server.logic.service;

import com.xinyue.game.server.dao.IDaoPlayerService;
import com.xinyue.game.server.dao.entity.PlayerEntity;
import com.xinyue.game.server.logic.handler.command.LoadRoleCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PlayerService {
    @Autowired
    private IDaoPlayerService daoPlayerService;

    public LoadRoleCommand.PlayerModel getPlayerModel(String userId, String playerId, String zoneId) {
        PlayerEntity playerEntity = daoPlayerService.getPlayerById(playerId);
        if (playerEntity != null) {
            if (playerEntity.getUserId().equals(userId) && playerEntity.getZoneId().equals(zoneId)) {
                LoadRoleCommand.PlayerModel playerModel = createPlayerModel(playerEntity);
                return playerModel;
            }
        }
        return null;
    }

    private LoadRoleCommand.PlayerModel createPlayerModel(PlayerEntity playerEntity) {
        LoadRoleCommand.PlayerModel playerModel = new LoadRoleCommand.PlayerModel();
        playerModel.setPlayerId(playerEntity.getPlayerId());
        playerModel.setNickName(playerEntity.getNickname());
        playerModel.setLevel(playerEntity.getLevel());
        playerModel.setExp(playerEntity.getExp());
        return playerModel;
    }
}
